Added public, private functions, fixed debugging