added exceptions and refactored code for new functions from filestore.php