Refactor main.js code and add initial database.js code