Code refactory on angular js.