Minor changes and removed stackoverflow exception