cleaned up and added functionality