More testing - code coverage 25%

- PHPUnit
- Refactoring
- Fixing some bugs