reduced code. still working