refactored alot.