Refactor some common code, use __LINE__ instead of __COUNTER__ where possible