Finalized implementation. Could use a bit of code clean-up. Some bugs still exist in code.