Added more comments and removed obsolete code