fixing stackoverflow error