source code changed to be more efficient