Fixes, cleanup and optimized.