refactor the code to handle high dimension vector space