Improved production code and extended unit tests