Modified to use here document based on an advice of @moosan63