Some reworking and refactoring of stuff