Simplified code structure
Optimized, tests updated