Clean up code style, return errors
Make main work with pointers