Fixed bugs and improved string manipulation