Size optimization and code cleanup