Added error codes and other functions