Used Shamos-Hoey. Added some more checks on errors and some gui feedback.