It is dirty, but this code needs to run as fast as possible.