Lots of rework/refactoring. Basic version logging to db