updated algorithm code that works on android to current build