shortened code and added missing functinoality