first attempt at cleanup & optimization