Added API command and fixed variable problems