Code seems to be working fine. Needs to be cleaned up though.