IMproved code for controlling motors