Removed dead code and added more comments