Code cleanup + preparations for new entity framework