refator directories and related code