added generic error handling and user login checks
added some wrappers and some more robust error handling