nightly - broke code into functions