changed main logic
fixed io bugs
added solving functions