optimized and print statements removed