refactored: reduced a function, and got more modularity and flexability.
Merge branches 'master' and 'refactor'