Gave credit to stackoverflow answer for code.