class modified to fix bugs