For correct functionality, merged to one file