some optimization on indexing
removes print statements