optimized more code and added even more comments