optimized certain parts of the code along with testing