Fixed direction conversion based on Richard's code