updated source code to use modified algorithm