refactored code and and cleared remaining comments