Added UnitTests and changed the code structure