Got original code working using JFunc to reduce code size.