update copyright header
update copyright header
separate out database code

improve conditional compiling
code tidy