Bug fixes, style changes, optimizations