Reorganized code and optimized imports