Database reading function added and several minor improvements