changed code to three functions, there is bug if there is no argument passed