Applies fixes as suggested by boombatower@