Various fixes, optimizations and features