Refactoring and Java API monitoring

Do not merge yet, this mainly outlines my current thinking and the changes I am making. I expect to be ready with the PR tomorrow.