Moved redirect handeling to seperated functions.