a few modifications from Steve Losh (A Modern Space Cadet)