added writer functionality and fixed db file bugs