integrating rest of code from v1

also made memory improvements using the Flash library