Added $database =~ s/\s*$// , fixed file format