Fixed several bugs, removed debug messages.