Refactored logic into more focused modules; added unit tests for bugs module