Major refactoring and bug fix for /index; Re-composed some functions to a separate file to reduce code bloat and improve reusability and performance.