Refactored jave as an object literal with methods, because otherwise the `this` keyword doesn't work properly without making it a fresh class and so on.