added debug stuff and safety