First more or less stable version but function behaves wrong