place entities more intelligently

*some fixes to compile under gcc