Added corner checking, removed some comments, renamed vars