Function and session errors fixed