Added better comments
Advanced version