bug fixes and removed ctx functions