Add monitoring and some cleanup & refactoring