Optimised the code

I made the code more concise, so that no lines of code are repeated. I
also removed the error string that came up when you used something
other than a 1 or 0 as the second parameter. Instead, an empty list is
now returned.