added beam optics functions in a new file. Other code clean up.