fixed bugs with code motion