Optimize/cleanup code