Hearts earned their first league victory outside of Edinburgh since January in a 2-0 win over struggling Motherwell.