Fixes and optimization