Small improvements and code cleanup