Some corrections after testing. Error handling modified. Some style-issues changed for better usability