Restructure files and folders.

Create lib directory, functions into different categories.