Refactored DatabaseManager and added some unit tests