Bug fixes, performance improvements & code cleanup