refactoring, fixed bug (created in this commit)