New entity movement code and some minor fixes