Replaced all the code for ghosting with a method.