optimsed and added comments