some bug fixes, unnecessary logic removed