now works as directive!
fixed bug with correct state on page load