refactored to command, improved logging+error handling