working, refactored with much cleaner code