update code based on results of tests and shorted the code