ported last changes to android, fixed indexing bug