Refactored alot.