big cleanup of redundant code, modularized into functions that interact with user