cleaned up code to within 80 line limit