Refactor of CSS loading related code