Added logic to serialize Error objects correctly

This should fix #97.