refactoring and fixing stupid mistakes