Cleaned up code, made more rigorous