The problem was that the last three statements were not being executed by line 54 ('if (dirs. == 0) return;') in the previous code. Those statements were originally being called from the 'act' method so that when this method exits, they would execute. When I moved them to the end of this method, they were being skipped over when only backward direction was possible (because of the 'return').