code cleanup, improved editing, add saving to db