Decoupled code and added tests