refactored, cleaner code