Support for multiple open files

Minor bugfixes and formatting improvement.