Cleanup the code a bit and fix types and add trial rotation