added beam file writing functionality