Added database functionality and minor improvements