cleaned up code, removed redundant database checks