Unit tests, refactoring and fixes
Added
Minor edits