Major refactoring by Vic...broken