Fixed bugs. Ready for encryption