Added stream locking and a file stream