Merged common code between rest and hal