Move some script logic out of the index

Signed-off-by: Cody Massin <keyosk@gmail.com>