fixed pop up bug, cleaned up code