Refactored and added more thorough tests
Separated some functional tests from unit tests