Some refactoring and added support for generating reports