SS: Major code refactoring