still not working, but cleaner code