refactored, made cleaner