Added error handling and fixed compression prefix

Also updated formatting to PSR standards and included method comments