Refactoring finished with full functionality. Pending more test cases.