Fixed bug in previous commit, code now works