Integrated prototype code with actual code. All working now