Again removing 7 line of duplication (with a BUG)
Removing code duplication, and logic errors
Removed non-sense and just plain wrong if{}else{} blocks
Removed non-sense and just plain wrong if{}else{} blocks
Updated checks, to be more sane