Added functions, removed nesting