Some minor improvements and code cleanup