code cleanup and maestro refactoring