Optimize and revamp to bash