code refactored, basic data save implemented