R+: Added last DM to database. Heavy code refactoring.