Debugged cleaned code; func