Added comments and did a cleanup of unused vars