Refactor .append() and .before()