Some cleanup of the code to make it tighter