Added some isset checks to avoid php notices.