improve error handling; clear method moved to common