Not always committing to database - needs some fixing