created dot_product function to achieve speed-up