Large refactoring (fix Utku's broken stuff :))