fixed paul's broken code