add useful toString methods and improve sanity check