Changed joystick code and possibly fixed memory issues (has not be tested).