Function slighty reorganized.

I realized some files were very messy. I'm planning to reorganize the code a little bit.