starting to optimize memory usage of code (only about 200 bytes free!)