Added unittests, cleaned up code and added domain functionality.