Added some fixes to the code. It should be good now just need to verify it one more time.