Adjusted the code base and added some tests