Refactored base code. Started repairing tests