general cleanup and added comments