Fixed bugs. Works with lists of length <6