Much better code, hopefully less confusing