refactored alot