change all beforeXXX to return error, not bool