Various debugging and API improvement