Fixed bug that caused stackoverflaw.