Add debug variables and fixed bugs