Performance and code improvements