Refractor

Optimize and made more readable.