Removed unused code and added function comments