Minor refactoring, renaming, comments etc.