Moving logic from index into relevant file