[improved] toInt function. More stable, works with strings too.