simplifying the algorithm
added a dot product convenience method