moved most functions into document ready