Added more debug statements and fixed even more bugs