Major code simplification and optimization v1.3