Organize structure, adding test cases

1. move database operations into a class in application views
2. adding test cases