Refactoring, added additional error checking. Added persistance

Signed-off-by: ozanturgut@gmail.com <ozanturgut@gmail.com>