made some significant changes needs testing