refactoring and removing unneccessary code