Code cleanup and fixed transform bug