Updated unit tests and added comments to complex logic