fix: optimizations and code cleanup