fixing bugs courtesy of @hyperlisk