Some cleanup to get rid of warnings
Major refactoring