Trying to get the stupid thing to work

Tried a more compact function but there is a problem with the if
statement on line 102 or how it is called on line 135