fixed bug & added comments