fixed 1.7.10, cleaned up code