Slight refactoring, getting ready for adding GUI