Simplified functional, but now its working in compiled code.