Add database restore function & code clean up