Resolved TODO: added comments and simplified code