Fix some bugs and missing variables