Cleaned up encryption code
Added couple unit tests