Fixed errors in upper hull calculation. Cleaned up code a bit.