Add test coverage and fix penalty code