bug fixes and main method